import {
  Get,
  Post,
  Param,
  Delete,
  DefaultValuePipe,
  ParseIntPipe,
  Body,
} from '@nestjs/common';
import { ThemeService } from './theme.service';
import { CreateThemeDto } from './dto/create-theme.dto';
import { UpdateThemeDto } from './dto/update-theme.dto';
import { ApiOperation } from '@nestjs/swagger';
import { GetUser } from '../auth/get-user.decorator';
import { User } from '../user/entities/user.entity';
import { Theme } from './entities/theme.entity';
import { ThemeFilterDto } from './dto/themeFilterDto';
import { Pagination } from '../utils/paginate';
import { WitAdmin } from '../auth/wit.admin';
import { ThemeBindUserDto } from './dto/bind-user.dto';
@WitAdmin('theme')
export class ThemeController {
  constructor(private readonly themeService: ThemeService) {}

  @ApiOperation({
    summary: '创建主题',
  })
  @Post('/createTheme')
  createTheme(
    @Body() createThemeDto: CreateThemeDto,
    @GetUser() user: User,
  ): Promise<string> {
    return this.themeService.create(createThemeDto, user);
  }

  @ApiOperation({
    summary: '获取所有主题数据',
  })
  @Post('/getThemeList')
  // @ApiImplicitParam({
  //   name: 'pageNum',
  //   required: false,
  // })
  // @ApiImplicitParam({
  //   name: 'pageSize',
  //   required: false,
  // })
  getThemeList(
    @Body() themeFilterDto: ThemeFilterDto,
    @Param('pageNum', new DefaultValuePipe(0), ParseIntPipe) pageNum: number,
    @Param('pageSize', new DefaultValuePipe(0), ParseIntPipe) pageSize: number,
    @GetUser() user: User,
  ): Promise<Pagination<Theme>> {
    const page = {
      page: pageNum,
      limit: pageSize > 100 ? 100 : pageSize,
    };
    return this.themeService.findAll(themeFilterDto, user, page);
  }

  @ApiOperation({
    summary: '获取指定主题数据',
  })
  @Get('/getThemeById/:id')
  getThemeById(@Param('id') id: string): Promise<Theme> {
    return this.themeService.findOne(id);
  }

  @ApiOperation({
    summary: '更新主题数据',
  })
  @Post('/updateTheme')
  update(@Body() updateThemeDto: UpdateThemeDto) {
    return this.themeService.update(updateThemeDto);
  }

  @ApiOperation({
    summary: '删除主题数据',
  })
  @Delete('/deleteTheme/:id')
  remove(@Param('id') id: string): Promise<void> {
    return this.themeService.remove(id);
  }
  @ApiOperation({
    summary: '主题绑定到用户',
  })
  @Post('/bindUser')
  bindUser(@Body() data: ThemeBindUserDto): Promise<string> {
    return this.themeService.bindUser(data);
  }
}
